<template>
	<view class="wrap">
		<u-navbar :back-icon-size="40" :is-back="true" :border-bottom="false" :title="navtitle">
			<view v-show="isShowNavbar" style="width: 100%;">
				<u-row>
					<u-col span="12" class="u-line-1" style="padding: 6rpx 10rpx 0;">
						<u-icon size="56" margin-left="10" label-size="26" :name="comment.url" :label="comment.name">
						</u-icon>
					</u-col>
				</u-row>
			</view>
			<view v-show="isShowNavbar" slot="right" style="padding: 0 30rpx;">
				<u-icon name="plus" size="24" label-size="24" label="关注" color="#ff9900" label-color="#ff9900"
					:custom-style="careBtnStyle">
				</u-icon>
			</view>
		</u-navbar>

		<view class="comment">
			<view class="top">
				<view class="left">
					<view class="heart-photo">
						<image :src="comment.url" mode=""></image>
					</view>
					<view class="user-info">
						<view class="name">
							{{ comment.name }}
							<u-tag class="aur-tag" text="楼主" size="mini" border-color="transparent"
								style="margin-left: 6rpx;" />
						</view>
						<view class="date">{{comment.date}}</view>
					</view>
				</view>
				<view class="right" :class="{ highlight: comment.isLike }">
					<u-icon name="plus" size="24" label-size="24" label="关注" color="#ff9900" label-color="#ff9900"
						:custom-style="careBtnStyle">
					</u-icon>
				</view>
			</view>
			<view class="content">
				<u-grid :col="2" :border="false">
					<block v-for="(item,index) in comment.contentImgs">
						<u-grid-item :custom-style="{padding:(index+1)%2==0&&index!==0?'0 0 10rpx':'0 10rpx 10rpx 0'}">
							<u-image border-radius="8" width="100%" height="300rpx" :src="item.imgurl"
								@click="imgPreview(item.imgurl)"></u-image>
						</u-grid-item>
					</block>
				</u-grid>
				{{ comment.contentText }}
			</view>
			<view class="bottom">
				<view class="left">
					<view class="likes">
						<block v-for="(item,index) in comment.topLikesAvatar.slice(0,3)">
							<image :src="item.imgurl" mode=""></image>
						</block>
						<u-icon class="liketxt" name="arrow-right" size="20" margin-right="0" label-size="24"
							:label="comment.likeNum+'人赞过'" label-pos="left"></u-icon>
					</view>
				</view>
				<view class="right" :class="{ highlight: comment.isLikes }">
					{{ comment.likeNum }}
					<u-icon v-if="!comment.isLikes" name="heart" class="like" color="#9a9a9a" :size="30"
						@click="getLike"></u-icon>
					<u-icon v-if="comment.isLikes" name="heart-fill" class="like" :size="30" @click="getLike">
					</u-icon>
				</view>
			</view>
		</view>
		<view class="all-reply">
			<view class="all-reply-top">全部回复</view>
			<view class="item" v-for="(item, index) in commentList" :key="index">
				<view class="comment">
					<view class="top">
						<view class="left">
							<view class="heart-photo">
								<image :src="item.url" mode=""></image>
							</view>
							<view class="user-info">
								<view class="name">{{ item.name }}</view>
								<view class="date">{{ item.date }}</view>
							</view>
						</view>
						<view class="right" :class="{ highlight: item.isLike }">
							<u-icon v-if="!item.isLike" name="heart" label-pos="left" :label="item.likeNum" class="like"
								:size="30" :label-size="26" color="#9a9a9a" @click="getLike(index)"></u-icon>
							<u-icon v-if="item.isLike" name="heart-fill" label-pos="left" :label="item.likeNum"
								class="like" :size="30" :label-size="26" @click="getLike(index)"></u-icon>
						</view>
					</view>
					<view class="reply" v-if="item.reply">
						<view class="text">
							<text style="font-size: 24rpx;">@</text>{{ item.reply.name }}:
							{{ item.reply.contentStr }}
						</view>
					</view>
					<view class="content">{{ item.contentText }}</view>
				</view>
			</view>
		</view>

		<!-- <u-tabbar></u-tabbar> -->
		<view class="cu-bar foot input">
			<u-row style="width: 100%;">
				<u-col span="9.4">
					<u-search search-icon="edit-pen" placeholder="拉近彼此的距离~从评论开始!" input-align="left"
						:show-action="false" :adjust-position="true">
					</u-search>
				</u-col>
				<u-col span="1.3" text-align="center">
					<u-icon name="heart" size="46" color="#777777"></u-icon>
				</u-col>
				<u-col span="1.3" text-align="center">
					<u-icon name="zhuanfa" size="46" color="#777777"></u-icon>
				</u-col>
			</u-row>
		</view>

		<u-modal v-model="showModal" :content="contentModal" :show-cancel-button="true"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				commentList: [],
				comment: '',
				showModal: false,
				contentModal: '兄嘚！不要因为我长得帅，就这样一直看着我！默默的喜欢就好了！',
				isShowNavbar: false,
				navtitle: "",
				careBtnStyle: {
					"border": "1px solid #ff9900",
					"padding": "9rpx 12rpx",
					"border-radius": "40rpx"
				}
			};
		},
		onPageScroll: function(Object) {
			if (Object.scrollTop >= 49) {
				this.navtitle = "";
				this.isShowNavbar = true;
			} else {
				this.navtitle = '共' + this.comment.allReply + '条回复';
				this.isShowNavbar = false;
			}
		},
		onLoad() {
			this.getReply();
		},
		methods: {
			//图片预览
			imgPreview(_imgurl) {
				if (_imgurl) {
					let imgs = [];
					imgs.push(_imgurl);
					uni.previewImage({
						indicator: "default",
						loop: true,
						urls: imgs
					});
				} else {
					this.contentModal = "预览图片加载失败，请稍后再试！";
					this.showModal = true;
				}
			},
			// 点赞
			getLike(index) {
				if (index === 0 || index > 0) {
					this.commentList[index].isLike = !this.commentList[index].isLike;
					if (this.commentList[index].isLike == true) {
						this.commentList[index].likeNum++;
					} else {
						this.commentList[index].likeNum--;
					}
				} else {
					if (this.comment.isLike == true) {
						this.comment.isLike = !this.comment.isLike;
						this.comment.likeNum--;
					} else {
						this.comment.isLike = !this.comment.isLike;
						this.comment.likeNum++;
					}
				}
			},
			// 回复列表
			getReply() {
				this.comment = {
					id: 1,
					name: '豆豆的小花衣',
					date: '03-09 11:30',
					contentText: '呐呐！这是妈妈给我买的小花衣，很喜欢！以后我要每次出门，都要穿在身上！',
					url: '/static/msgIcon/baby.png',
					allReply: 12,
					likeNum: 33,
					isLikes: false,
					contentImgs: [{
						imgurl: "/static/msgIcon/clothes.jpg"
					}, {
						imgurl: "/static/msgIcon/clothes1.jpg"
					}, {
						imgurl: "/static/msgIcon/clothes2.jpg"
					}, {
						imgurl: "/static/msgIcon/clothes3.jpg"
					}],
					topLikesAvatar: [{
							imgurl: "/static/msgIcon/mom.jpg"
						},
						{
							imgurl: "/static/msgIcon/kbz.png"
						},
						{
							imgurl: "https://cdn.uviewui.com/uview/template/SmilingDog.jpg"
						}
					]
				};

				//初始化标题
				this.navtitle = '共' + this.comment.allReply + '条回复';

				this.commentList = [{
						name: 'Lily',
						date: '07-22 11:40',
						contentText: '豆豆穿上这件小花衣，真的不要太好看，棒棒哒！',
						allReply: 0,
						likeNum: 722,
						url: '/static/msgIcon/mom.jpg',
						isLike: true
					}, {
						name: '快帮主',
						date: '03-14 18:00',
						contentText: '点赞+1',
						url: '/static/msgIcon/kbz.png',
						likeNum: 33,
						isLike: false,
						reply: {
							name: 'Lily',
							contentStr: '豆豆穿上这件小花衣，真的不要太好看，棒棒哒！'
						}
					},
					{
						name: '川蜀鄂余',
						date: '07-25 13:58',
						url: '/static/msgIcon/dad.jpg',
						contentText: '确实好好看，爱了，爱了！',
						allReply: 0,
						likeNum: 11,
						isLike: false,
						reply: {
							name: 'Lily',
							contentStr: '豆豆穿上这件小花衣，真的不要太好看，棒棒哒！'
						}
					},
					{
						name: '蜀味正道',
						date: '08-23 17:38',
						contentText: '这也太可爱了吧，好萌萌哒的样子！',
						allReply: 0,
						likeNum: 21,
						url: '/static/msgIcon/other.jpg',
						isLike: false,
						allReply: 2,
						reply: {
							name: 'Lily',
							contentStr: '豆豆穿上这件小花衣，真的不要太好看，棒棒哒！'
						}
					},
					{
						name: '余李同行',
						date: '06-20 13:58',
						contentText: '这是见过最好看、最搭的风格了，真的好喜欢，求告知连接！',
						allReply: 0,
						likeNum: 150,
						url: 'https://cdn.uviewui.com/uview/template/SmilingDog.jpg',
						isLike: false
					}
				];
			}
		}
	};
</script>

<style lang="scss" scoped>
	@import "footBar.css";

	page {
		background-color: #f2f2f2;
	}

	.comment {
		padding: 20rpx 30rpx 20rpx;
		font-size: 28rpx;
		letter-spacing: 0.05rem;
		color: #555555;
		background-color: #ffffff;

		.top,
		.bottom {
			display: flex;
			justify-content: space-between;
		}

		.left {
			display: flex;

			.heart-photo {
				image {
					width: 64rpx;
					height: 64rpx;
					border-radius: 50%;
					background-color: #f2f2f2;
				}
			}

			.likes {
				margin: 14rpx 0 0 70rpx;

				image {
					width: 44rpx;
					height: 44rpx;
					border-radius: 50%;
					background-color: #f2f2f2;
					margin-right: 10rpx;
				}

				.liketxt {
					position: absolute;
					margin-top: 10rpx;
				}
			}

			.user-info {
				margin-left: 10rpx;

				.name {
					// color: #5677fc;
					font-size: 26rpx;
					margin-bottom: 4rpx;
					font-weight: bold;
				}

				.date {
					font-size: 20rpx;
					color: $u-light-color;
				}
			}
		}

		.right {
			display: flex;
			font-size: 20rpx;
			// align-items: center;
			align-items: start;
			color: #9a9a9a;

			.like {
				margin-left: 6rpx;
			}

			.num {
				font-size: 26rpx;
				color: #9a9a9a;
			}
		}

		.bottom {
			.right {
				display: flex;
				font-size: 26rpx;
				align-items: center;
				// color: #9a9a9a;

				.like {
					margin-left: 6rpx;
				}

				.num {
					font-size: 26rpx;
					color: #9a9a9a;
				}
			}
		}

		.content {
			margin: 14rpx 0 0 70rpx;
		}

		.highlight {
			.like {
				color: #fa3534;
			}

			.num {
				color: #fa3534;
			}
		}
	}

	.all-reply {
		margin-top: 10rpx;
		padding-top: 20rpx;
		background-color: #ffffff;

		.all-reply-top {
			margin-left: 20rpx;
			// padding-left: 20rpx;
			// border-left: solid 4rpx #5677fc;
			font-size: 30rpx;
			font-weight: bold;
		}

		.item {
			// border-bottom: solid 2rpx $u-border-color;
		}

		.reply {
			padding: 20rpx;
			// background-color: rgb(242, 242, 242);
			border-radius: 12rpx;
			margin: 10rpx 0 0 70rpx;
			background-color: #fbfbfb;
			color: #7d7b7b;

			.username {
				font-size: 24rpx;
				color: #7a7a7a;
			}
		}
	}
</style>
